home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / tar.gnu / sprite / tar.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-29  |  10.0 KB  |  333 lines

  1. /*
  2.  
  3.     Copyright (C) 1988 Free Software Foundation
  4.  
  5. GNU tar is distributed in the hope that it will be useful, but WITHOUT ANY
  6. WARRANTY.  No author or distributor accepts responsibility to anyone
  7. for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.
  9. Refer to the GNU tar General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute GNU tar,
  12. but only under the conditions described in the GNU tar General Public
  13. License.  A copy of this license is supposed to have been given to you
  14. along with GNU tar so you can know your rights and responsibilities.  It
  15. should be in a file named COPYING.  Among other things, the copyright
  16. notice and this notice must be preserved on all copies.
  17.  
  18. In other words, go ahead and share GNU tar, but don't try to stop
  19. anyone else from sharing it farther.  Help stamp out software hoarding!
  20. */
  21.  
  22. /*
  23.  * Header file for tar (tape archive) program.
  24.  *
  25.  * @(#)tar.h 1.24 87/11/06
  26.  *
  27.  * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  28.  */
  29.  
  30. #ifdef sprite
  31. #define DEFBLOCKING 8
  32. #define ALLOW_NO_RECURSE
  33. #define ALLOW_LONG_NAMES
  34. #endif
  35.  
  36. /*
  37.  * Kludge for handling systems that can't cope with multiple
  38.  * external definitions of a variable.  In ONE routine (tar.c),
  39.  * we #define TAR_EXTERN to null; here, we set it to "extern" if
  40.  * it is not already set.
  41.  */
  42. #ifndef TAR_EXTERN
  43. #define TAR_EXTERN extern
  44. #endif
  45.  
  46. #ifdef USG
  47. typedef int size_t;
  48. #endif
  49.  
  50. /*
  51.  * Header block on tape.
  52.  *
  53.  * I'm going to use traditional DP naming conventions here.
  54.  * A "block" is a big chunk of stuff that we do I/O on.
  55.  * A "record" is a piece of info that we care about.
  56.  * Typically many "record"s fit into a "block".
  57.  */
  58. #define    RECORDSIZE    512
  59. #define    NAMSIZ        100
  60. #define    TUNMLEN        32
  61. #define    TGNMLEN        32
  62. #define SPARSE_EXT_HDR  21
  63. #define SPARSE_IN_HDR    4
  64.  
  65. struct sparse {
  66.     char offset[12];
  67.     char numbytes[12];
  68. };
  69.  
  70. struct sp_array {
  71.     int offset;
  72.     int numbytes;
  73. };
  74.  
  75. #define HDR_MAGIC 0xa3
  76.  
  77. union record {
  78.     char        charptr[RECORDSIZE];
  79.     struct header {
  80.         char    name[NAMSIZ];
  81.         char    mode[8];
  82.         char    uid[8];
  83.         char    gid[8];
  84.         char    size[12];
  85.         char    mtime[12];
  86.         char    chksum[8];
  87.         char    linkflag;
  88.         char    linkname[NAMSIZ];
  89.         char    magic[8];
  90.         char    uname[TUNMLEN];
  91.         char    gname[TGNMLEN];
  92.         char    devmajor[8];
  93.         char    devminor[8];
  94.         /* these following fields were added by JF for gnu */
  95.         /* and are NOT standard */
  96.         char    atime[12];
  97.         char    ctime[12];
  98.         char    offset[12];
  99.         char    longnames[4];
  100.         struct    sparse sp[SPARSE_IN_HDR];
  101.         char    isextended;
  102.         char    realsize[12];         /* true size of the sparse file */
  103.         unsigned char hdr_magic;
  104. /*        char    ending_blanks[12];*/ /* number of nulls at the
  105.                            end of the file, if any */
  106.     } header;
  107.     struct extended_header {
  108.         unsigned char xh_isextended; /* non-zero -> continued in
  109.                           * next record */
  110.         unsigned char xh_type;
  111.         unsigned char xh_magic;
  112.         union {
  113.             struct sparse _xh_sp[21];
  114.             /* 
  115.              * The buffer is only 508 characters so that the string 
  116.              * stored in it will be null-terminated
  117.              */
  118.             char _xh_namebuf[508];
  119.         } u;
  120.     } ext_hdr;
  121. };
  122.  
  123. #define xh_sp           u._xh_sp
  124. #define xh_namebuf      u._xh_namebuf
  125.  
  126. /* 
  127.  * Non-ASCII magic number to distinguish a header with GNU extensions from 
  128.  * a Posix header with a prefixed name.  (A Posix header would have either 
  129.  * an ASCII character or a null.) (XXX what about 8-bit character sets?)
  130.  */
  131. #define XH_MAGIC        0xab
  132.  
  133. /* Flags telling what types of extended header records follow. */
  134. #define XH_FILENAME     1
  135. #define XH_LINKNAME     2
  136. #define XH_SPARSE_FILE  4
  137.  
  138. /* The checksum field is filled with this while the checksum is computed. */
  139. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  140.  
  141. /* The magic field is filled with this if uname and gname are valid. */
  142. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  143.  
  144. /* The linkflag defines the type of file */
  145. #define    LF_OLDNORMAL    '\0'        /* Normal disk file, Unix compat */
  146. #define    LF_NORMAL    '0'        /* Normal disk file */
  147. #define    LF_LINK        '1'        /* Link to previously dumped file */
  148. #define    LF_SYMLINK    '2'        /* Symbolic link */
  149. #define    LF_CHR        '3'        /* Character special file */
  150. #define    LF_BLK        '4'        /* Block special file */
  151. #define    LF_DIR        '5'        /* Directory */
  152. #define    LF_FIFO        '6'        /* FIFO special file */
  153. #define    LF_CONTIG    '7'        /* Contiguous file */
  154. /* Further link types may be defined later. */
  155. #ifdef sprite
  156. #define LF_RMTLINK    '8'        /* Remote link, kind of symbolic link */
  157. #define LF_PSEUDODEV    '9'        /* Pseudo-device (for server process) */
  158. #endif /* sprite */
  159.  
  160. #define LF_DUMPDIR    'D'        /* This is a dir entry that contains
  161.                        the names of files that were in
  162.                        the dir at the time the dump
  163.                        was made */
  164. #define LF_MULTIVOL    'M'        /* This is the continuation
  165.                        of a file that began on another
  166.                        volume */
  167. #define LF_SPARSE    'S'        /* This is for sparse files */
  168. #define LF_VOLHDR    'V'        /* This file is a tape/volume header */
  169.                     /* Ignore it on extraction */
  170.  
  171. /*
  172.  * Exit codes from the "tar" program
  173.  */
  174. #define    EX_SUCCESS    0        /* success! */
  175. #define    EX_ARGSBAD    1        /* invalid args */
  176. #define    EX_BADFILE    2        /* invalid filename */
  177. #define    EX_BADARCH    3        /* bad archive */
  178. #define    EX_SYSTEM    4        /* system gave unexpected error */
  179.  
  180.  
  181. /*
  182.  * Global variables
  183.  */
  184. TAR_EXTERN union record    *ar_block;    /* Start of block of archive */
  185. TAR_EXTERN union record    *ar_record;    /* Current record of archive */
  186. TAR_EXTERN union record    *ar_last;    /* Last+1 record of archive block */
  187. TAR_EXTERN char        ar_reading;    /* 0 writing, !0 reading archive */
  188. TAR_EXTERN int        blocking;    /* Size of each block, in records */
  189. TAR_EXTERN int        blocksize;    /* Size of each block, in bytes */
  190. TAR_EXTERN char        *ar_file;    /* File containing archive */
  191. TAR_EXTERN char        *info_script;    /* Script to run at end of each tape change */
  192. TAR_EXTERN char        *name_file;    /* File containing names to work on */
  193. TAR_EXTERN char        *tar;        /* Name of this program */
  194. TAR_EXTERN struct sp_array *sparsearray;/* Pointer to the start of the scratch space */
  195. TAR_EXTERN int        sp_array_size;    /* Initial size of the sparsearray */
  196. TAR_EXTERN char        *current_filename; /* file name for current header */
  197. TAR_EXTERN char        *current_linkname; /* link name for current header */
  198.  
  199. /*
  200.  * Flags from the command line
  201.  */
  202. TAR_EXTERN int cmd_mode;
  203. #define CMD_NONE    0
  204. #define CMD_CAT        1        /* -A */
  205. #define CMD_CREATE    2        /* -c */
  206. #define CMD_DIFF    3        /* -d */
  207. #define CMD_APPEND    4        /* -r */
  208. #define CMD_LIST    5        /* -t */
  209. #define CMD_UPDATE    6        /* -u */
  210. #define CMD_EXTRACT    7        /* -x */
  211. #define CMD_DELETE    8        /* -D */
  212.  
  213.                     /* -[0-9][lmh] */
  214.             /* CMD_CAT       -A */
  215.                     /* -b */
  216. TAR_EXTERN int    f_reblock;        /* -B */
  217.             /* CMD_CREATE       -c */
  218.                     /* -C */
  219.             /* CMD_DIFF       -d */
  220. /* TAR_EXTERN char    f_dironly;    /* -D */
  221. TAR_EXTERN int    f_debug;            /* -e */
  222.                     /* -f */
  223. TAR_EXTERN int    f_run_script_at_end;    /* -F */
  224. TAR_EXTERN int     f_gnudump;        /* -G */
  225. TAR_EXTERN int    f_follow_links;        /* -h */
  226. TAR_EXTERN int    f_ignorez;        /* -i */
  227.             /* CMD_DELETE       -J */
  228. TAR_EXTERN int    f_keep;            /* -k */
  229. TAR_EXTERN int    f_startfile;        /* -K */
  230. TAR_EXTERN int    f_local_filesys;    /* -l */
  231. TAR_EXTERN int    f_long_names;        /* -L */
  232. TAR_EXTERN int    f_modified;        /* -m */
  233. TAR_EXTERN int     f_multivol;        /* -M */
  234. TAR_EXTERN int  f_no_recurse;           /* -n */
  235. TAR_EXTERN int    f_new_files;        /* -N */
  236. TAR_EXTERN int    f_oldarch;        /* -o */
  237. TAR_EXTERN int  f_exstdout;        /* -O */
  238. TAR_EXTERN int    f_use_protection;    /* -p */
  239. TAR_EXTERN int  f_absolute_paths;    /* -P */
  240. TAR_EXTERN int    f_sayblock;        /* -R */
  241. TAR_EXTERN int    f_sorted_names;        /* -s */
  242. TAR_EXTERN int    f_sparse_files;        /* -S  ... JK */
  243. TAR_EXTERN int    f_namefile;        /* -T */
  244.             /* CMD_UPDATE       -u */
  245. TAR_EXTERN int    f_verbose;        /* -v */
  246. TAR_EXTERN char *f_volhdr;        /* -V */
  247. TAR_EXTERN int  f_confirm;        /* -w */
  248. TAR_EXTERN int  f_verify;        /* -W */
  249.             /* CMD_EXTRACT     -x */
  250. TAR_EXTERN int  f_exclude;        /* -X */
  251. TAR_EXTERN int     f_compress;        /* -z */
  252.                     /* -Z */
  253.  
  254. /*
  255.  * We now default to Unix Standard format rather than 4.2BSD tar format.
  256.  * The code can actually produce all three:
  257.  *    f_standard    ANSI standard
  258.  *    f_oldarch    V7
  259.  *    neither        4.2BSD
  260.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  261.  * The only advantage to the "neither" option is that we can cmp our
  262.  * output to the output of 4.2BSD tar, for debugging.
  263.  */
  264. #define        f_standard        (!f_oldarch)
  265.  
  266. /*
  267.  * Structure for keeping track of filenames and lists thereof.
  268.  */
  269. struct name {
  270.     struct name    *next;
  271.     short        length;        /* cached strlen(name) */
  272.     char        found;        /* A matching file has been found */
  273.     char        firstch;    /* First char is literally matched */
  274.     char        regexp;        /* This name is a regexp, not literal */
  275.     char        *change_dir;    /* JF set with the -C option */
  276.     char        *dir_contents;    /* JF for f_gnudump */
  277.     char        name[NAMSIZ+1];
  278. };
  279.  
  280. TAR_EXTERN struct name    *namelist;    /* Points to first name in list */
  281. TAR_EXTERN struct name    *namelast;    /* Points to last name in list */
  282.  
  283. TAR_EXTERN int        archive;    /* File descriptor for archive file */
  284. TAR_EXTERN int        errors;        /* # of files in error */
  285.  
  286. /*
  287.  *
  288.  * Due to the next struct declaration, each routine that includes
  289.  * "tar.h" must also include <sys/types.h>.  I tried to make it automatic,
  290.  * but System V has no defines in <sys/types.h>, so there is no way of
  291.  * knowing when it has been included.  In addition, it cannot be included
  292.  * twice, but must be included exactly once.  Argghh!
  293.  *
  294.  * Thanks, typedef.  Thanks, USG.
  295.  */
  296. struct link {
  297.     struct link    *next;
  298.     dev_t        dev;
  299.     ino_t        ino;
  300.     short        linkcount;
  301.     char        name[NAMSIZ+1];
  302. };
  303.  
  304. TAR_EXTERN struct link    *linklist;    /* Points to first link in list */
  305.  
  306.  
  307. /*
  308.  * Error recovery stuff
  309.  */
  310. TAR_EXTERN char        read_error_flag;
  311.  
  312.  
  313. /*
  314.  * Declarations of functions available to the world.
  315.  */
  316. union record *findrec();
  317. void userec();
  318. union record *endofrecs();
  319. void anno();
  320. char *extended_header_type_name();
  321. void get_names();
  322.  
  323. /* Do not prototype these for BSD--see port.c [DOPRNT_MSG].  */
  324. #if defined(__STDC__) && (!defined(BSD42) || defined(sprite))
  325. void msg(char *, ...);
  326. void msg_perror(char *, ...);
  327. #else
  328. void msg();
  329. void msg_perror();
  330. #endif
  331. /* #define     annorec(stream, msg)    anno(stream, msg, 0)    /* Cur rec */
  332. /* #define    annofile(stream, msg)    anno(stream, msg, 1)    /* Saved rec */
  333.